<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<html lang="zh-CN">
<head>
    <title>手工执行存储过程</title>
    <meta name="decorator" content="default"/>
</head>
<body>
<%--<ul class="nav nav nav-pills">
    <li class="active"><a href="${ctx}/call/config/callConfig/">呼叫设置</a></li>
</ul>--%>
<sys:message content="${message}"/>
<form:form id="searchForm" modelAttribute="callConfig" action="${ctx}/call/config/callConfig/view" method="post"
           cssClass="form-search">
    <table class="table">
        <!--班次设置-->
        <shiro:hasPermission name="call:config:callConfig:updateconfig">
            <tr>
                <td style="width: 600px;">
                    <ul class="ul-form">
                        <li>
                            <div class="input-prepend">
                                <span class="add-on">上午班次开始</span>
                                <form:input readonly="true" path="workShift1start" type="text" class="input-medium"
                                            onmousedown="WdatePicker({dateFmt:'HH:mm:ss'})"/>
                            </div>
                            <div class="input-prepend">
                                <span class="add-on">上午班次结束</span>
                                <form:input readonly="true" path="workShift1end" type="text" class="input-medium"
                                            onmousedown="WdatePicker({dateFmt:'HH:mm:ss'})"/>

                            </div>
                        </li>
                    </ul>
                    <ul class="ul-form">
                        <li>
                            <div class="input-prepend">
                                <span class="add-on">下午班次开始</span>
                                <form:input readonly="true" path="workShift2start" type="text" class="input-medium"
                                            onmousedown="WdatePicker({dateFmt:'HH:mm:ss'})"/>
                            </div>
                            <div class="input-prepend">
                                <span class="add-on">下午班次结束</span>
                                <form:input readonly="true" path="workShift2end" type="text" class="input-medium"
                                            onmousedown="WdatePicker({dateFmt:'HH:mm:ss'})"/>
                            </div>
                        </li>
                    </ul>
                </td>
                <td>
                    <button id="workShiftBtn" type="button" class="btn btn-primary btn-large">
                        <i class="icon-user icon-white"></i>班次修改
                    </button>
                </td>
            </tr>
            <!--通话设置-->
            <tr>
                <td>
                    <ul class="ul-form">
                        <li>
                            <div class="input-prepend">
                                <span class="add-on">较长通话秒数</span>
                                <form:input path="longCallSec" type="text" class="input-medium"/>
                            </div>
                            <div class="input-prepend">
                                <span class="add-on">超时接通秒数</span>
                                <form:input path="timeOutSec" type="text" class="input-medium"/>
                            </div>
                        </li>
                        <li>
                            <div class="input-prepend">
                                <span class="add-on">快速接听秒数</span>
                                <form:input path="quickRingSec" type="text" class="input-medium"/>
                            </div>
                            <div class="input-prepend">
                                <span class="add-on">最后统计时间</span>
                                <form:input path="workEndTime" type="text" class="input-medium" readonly="true"
                                            onmousedown="WdatePicker({dateFmt:'HH:mm:ss'})"/>
                            </div>
                        </li>
                    </ul>
                </td>
                <td>
                    <button id="callingBtn" type="button" class="btn btn-primary btn-large">
                        <i class="icon-time icon-white"></i>通话修改
                    </button>
                </td>
            </tr>
            <!--内部参数修改-->
            <%--<tr>
                <td>
                    <ul class="ul-form">

                    </ul>
                </td>
                <td>
                    <button id="rateBtn" type="button" class="btn btn-primary btn-large">
                        <i class="icon-volume-up icon-white"></i>参数修改
                    </button>
                </td>
            </tr>--%>
        </shiro:hasPermission>
        <shiro:hasPermission name="call:config:callConfig:group">
            <tr style="height: 100px;">
                <td>
                    <table>
                        <tr>
                            <td style="border-top: 0px;">
                                <form:select path="" id="outallgroups" items="${config.outAllGroups}"
                                             style="height: 100px;" multiple="multiple"/>
                            </td>
                            <td style="border-top: 0px;">
                                <button id="outaddBtn" type="button" class="btn btn-small btn-primary btn-block"><i
                                        class="icon-arrow-right icon-white"></i></button>
                                <button id="outdelBtn" type="button" class="btn btn-small btn-primary btn-block"><i
                                        class="icon-arrow-left icon-white"></i></button>
                            </td>
                            <td style="border-top: 0px;">
                                <form:select path="" id="outgroups" items="${config.outGroups}"
                                             style="height: 100px;" multiple="multiple"/>
                            </td>
                        </tr>
                    </table>
                </td>
                <td>
                    <button id="outGroupBtn" type="button" class="btn btn-primary btn-large">
                        <i class="icon-leaf icon-white"></i>呼出部门
                    </button>
                </td>
            </tr>
            <tr style="height: 100px;">
                <td>
                    <table>
                        <tr>
                            <td style="border-top: 0px;">
                                <form:select path="" id="inallgroups" items="${config.inAllGroups}"
                                             style="height: 100px;" multiple="multiple"/>
                            </td>
                            <td style="border-top: 0px;">
                                <button id="inaddBtn" type="button" class="btn btn-small btn-primary btn-block"><i
                                        class="icon-arrow-right icon-white"></i></button>
                                <button id="indelBtn" type="button" class="btn btn-small btn-primary btn-block"><i
                                        class="icon-arrow-left icon-white"></i></button>
                            </td>
                            <td style="border-top: 0px;">
                                <form:select path="" id="ingroups" items="${config.inGroups}"
                                             style="height: 100px;" multiple="multiple"/>
                            </td>
                        </tr>
                    </table>
                </td>
                <td>
                    <button id="inGroupBtn" type="button" class="btn btn-primary btn-large">
                        <i class="icon-leaf icon-white"></i>呼入部门
                    </button>
                </td>
            </tr>

        </shiro:hasPermission>
        <shiro:hasPermission name="call:config:callConfig:execute">
            <tr>
                <td>
                </td>
                <td>
                    <button id="excuteBtn" type="button" class="btn btn-primary btn-large">
                        <i class="icon-indent-left icon-white"></i>手工执行
                    </button>
                </td>
            </tr>
        </shiro:hasPermission>
    </table>
    <input id="callConfigType" name="callConfigType" type="hidden"/>
</form:form>

<script type="text/javascript">
    $(document).ready(function () {
        function ajaxUpdate(obj) {
            loading("正在执行,请稍后");
            if (obj != null && obj != undefined) {
                obj.attr("disabled", "disabled");
            }
            var parm = $("#searchForm").serialize();
            $.ajax({
                       url: "${ctx}/call/config/callConfig/update/",
                       type: "post",
                       dataType: "json",
                       data: parm,
                       success: function (data) {
                           closeTip();
                           if (obj != null && obj != undefined) {
                               obj.removeAttr("disabled");
                           }
                           if (data.state) {
                               showTip(data.message, "更新成功", 1000, 1);
                           } else {
                               alertx(data.message, null, '更新失败');
                           }
                       },
                       error: function (data) {
                           closeTip();
                           if (obj != null && obj != undefined) {
                               obj.removeAttr("disabled");
                           }
                           var message = "";
                           if (data.status = "500") {
                               var _f = $("<div/>");
                               var _div = $("<div/>").html(data.responseText);
                               _div.css("width", "100%");
                               _div.css("height", 300);
                               _div.css("overflow", "auto");
                               _div.css("border", "1px solid #000000");
                               _div.appendTo(_f);
                               message = _f.html();
                           } else {
                               message = data.responseText;
                           }
                           alertx(message, null, '错误[' + data.status + ']');
                       }
                   });
        }

        function ajaxUpdateGroup(_btn,array,type){
            $.ajax({
                       url: "${ctx}/call/config/callConfig/group/",
                       type: "post",
                       dataType: "json",
                       data: {"groupList": array,"type":type},
                       success: function (data) {
                           closeTip();
                           _btn.removeAttr("disabled");
                           if (data.state) {
                               showTip(data.message, "执行成功", 1000, 1);
                           } else {
                               alertx(data.message, null, '执行失败');
                           }
                       },
                       error: function (data) {
                           closeTip();
                           _btn.removeAttr("disabled");
                           var message = "";
                           if (data.status = "500") {
                               var _f = $("<div/>");
                               var _div = $("<div/>").html(data.responseText);
                               _div.css("width", "100%");
                               _div.css("height", 300);
                               _div.css("overflow", "auto");
                               _div.css("border", "1px solid #000000");
                               _div.appendTo(_f);
                               message = _f.html();
                           } else {
                               message = data.responseText;
                           }
                           alertx(message, null, '错误[' + data.status + ']');
                       }
                   });
        }

        $("#workShiftBtn").click(function () {
            $("#callConfigType").val("WORKSHIFT");
            ajaxUpdate($(this));
        });

        $("#callingBtn").click(function () {
            $("#callConfigType").val("CALLING");
            ajaxUpdate($(this));
        });

        /*$("#rateBtn").click(function () {
            $("#callConfigType").val("RATE");
            ajaxUpdate($(this));
        });*/
        $("#excuteBtn").click(function () {
            $("#callConfigType").val("EXECUTE");
            loading("正在执行,请稍后");
            var _btn = $(this);
            _btn.attr("disabled", "disabled");
            $.ajax({
                       url: "${ctx}/call/config/callConfig/excute/",
                       type: "post",
                       dataType: "json",
                       success: function (data) {
                           closeTip();
                           _btn.removeAttr("disabled");
                           if (data.state) {
                               showTip(data.message, "执行成功", 1000, 1);
                           } else {
                               alertx(data.message, null, '执行失败');
                           }
                       },
                       error: function (data) {
                           closeTip();
                           _btn.removeAttr("disabled");
                           var message = "";
                           if (data.status = "500") {
                               var _f = $("<div/>");
                               var _div = $("<div/>").html(data.responseText);
                               _div.css("width", "100%");
                               _div.css("height", 300);
                               _div.css("overflow", "auto");
                               _div.css("border", "1px solid #000000");
                               _div.appendTo(_f);
                               message = _f.html();
                           } else {
                               message = data.responseText;
                           }
                           alertx(message, null, '错误[' + data.status + ']');
                       }
                   });
        });
        $("#outaddBtn").click(function () {
            var values = $("#outallgroups option:selected");
            if (values.length > 0) {
                $(values).each(function (i) {
                    $(this).appendTo($("#outgroups"));
                });
            } else {
                alert("您需要选择至少一个");
            }
        });
        $("#outdelBtn").click(function () {
            var values = $("#outgroups option:selected");
            if (values.length > 0) {
                $(values).each(function (i) {
                    $(this).appendTo($("#outallgroups"));
                });
            } else {
                alert("您需要选择至少一个");
            }
        });
        $("#outGroupBtn").click(function () {
            loading("正在执行,请稍后");
            var _btn = $(this);
            _btn.attr("disabled", "disabled");
            var array = new Array();
            $("#outgroups option").each(function (i) {
                array.push($(this).val());
            });
            ajaxUpdateGroup(_btn,array,"OUTGROUP");
        });

        $("#inaddBtn").click(function () {
            var values = $("#inallgroups option:selected");
            if (values.length > 0) {
                $(values).each(function (i) {
                    $(this).appendTo($("#ingroups"));
                });
            } else {
                alert("您需要选择至少一个");
            }
        });
        $("#indelBtn").click(function () {
            var values = $("#ingroups option:selected");
            if (values.length > 0) {
                $(values).each(function (i) {
                    $(this).appendTo($("#inallgroups"));
                });
            } else {
                alert("您需要选择至少一个");
            }
        });
        $("#inGroupBtn").click(function () {
            loading("正在执行,请稍后");
           var _btn = $(this);
            _btn.attr("disabled", "disabled");
            var array = new Array();
            $("#ingroups option").each(function (i) {
                array.push($(this).val());
            });
            ajaxUpdateGroup(_btn,array,"INGROUP");
        });

    });
</script>
</body>
</html>